package com.zhl.hadoop.mapreduce.combiner;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @program: demos
 * @description: 规约组件
 * 在每一个maptask节点上运行，reduce是汇总之后才会运行
 * 父类是reducer
 * 汇总局部结果，减少网络传输消耗，提高效率
 * @author: 刘振华
 * @create: 2020-10-29 12:05
 **/
public class WordCountCombiner extends Reducer<Text, LongWritable,Text,LongWritable> {
	@Override
	protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
		int time = 0;
		for (LongWritable value : values) {
			time++;
		}
		context.write(key,new LongWritable(time));
	}
}
